package com.junmeng.libfloating.tab

import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.provider.Settings
import android.view.View
import com.junmeng.lib.ui.topview.core.WindowTopViewManager

/**
 * 进入开发者选项
 */
class MenuEnterDevOptions : TabMenu.Item() {
    private var clickListener = View.OnClickListener {
        startDevelopmentActivity()
    }

    override fun getClickListener(): View.OnClickListener? {
        return clickListener
    }

    override fun getLabel(): String {
        return "开发者选项"
    }

    /**
     * 打开开发者模式界面
     */
    private fun startDevelopmentActivity() {
        val context: Context? = WindowTopViewManager.getCurrentActivity()
        try {
            val intent = Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS)
            context?.startActivity(intent)
        } catch (e: Exception) {
            try {
                val componentName = ComponentName(
                    "com.android.settings",
                    "com.android.settings.DevelopmentSettings"
                )
                val intent = Intent()
                intent.component = componentName
                intent.action = "android.intent.action.View"
                context?.startActivity(intent)
            } catch (e1: Exception) {
                try {
                    val intent =
                        Intent("com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS") //部分小米手机采用这种方式跳转
                    context?.startActivity(intent)
                } catch (e2: Exception) {
                }
            }
        }
    }
}